mod pendulum;

use ggez::{Context, GameResult, GameError, graphics, glam::Vec2};

pub struct State{
    pendulums: Vec<pendulum::Pendulum>,
}

impl State{
    pub fn new() -> State {
        let mut pendulums: Vec<pendulum::Pendulum> = vec![];
        for _i in 0..1 {
            let origin = Vec2{x: 400.0,y: 0.0};
            let r = 500.0;
            let pendulum = pendulum::Pendulum::new(origin, r);
            pendulums.push(pendulum);
        }
        State { pendulums }
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        for pendulum in &mut self.pendulums {pendulum.update()}
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        for pendulum in &mut self.pendulums {pendulum.display(ctx, &mut canvas)}
        canvas.finish(ctx)?;
        Ok(())
    }
}